<template>
	<view class="container">
		<view v-if="props.isShowLeft" class="left" @click="() => emits('leftClickHandle')">
			<image src="https://jdyd-marketing-public.oss-cn-hangzhou.aliyuncs.com/yx/34fb082f-8960-475b-aefe-9dfef45b62fb.png"></image>
			<text>{{ agentInfo.agentName }}</text>
		</view>
		<view v-if="props.isShowRight" class="right" @click="() => emits('rightClickHandle')">
			<image src="https://jdyd-marketing-public.oss-cn-hangzhou.aliyuncs.com/yx/de44fa04-bd81-4320-ae9c-1b9c7cea8964.png"></image>
			<text>重新定位</text>
		</view>
	</view>
</template>

<script setup>
	import {} from '@dcloudio/uni-app'
	import { ref, onMounted, defineProps, defineEmits, getCurrentInstance } from 'vue'
	import appConfig from '@/config/appConfig.js'
	import storageManage from '@/util/storageManage.js'
	
	const { $infoBox } = getCurrentInstance().appContext.config.globalProperties
	
	// 左侧点击事件 （通知首页跳转地址选择列表）
	// 右侧点击事件 通知外部授权定位信息
	const emits = defineEmits(['leftClickHandle','rightClickHandle'])
	
	const props = defineProps({
		isShowLeft: { type: Boolean, default: true },
		isShowRight: { type: Boolean, default: true }
	})
	const agentInfo = ref({})
	onMounted(() => {
		agentInfo.value = storageManage.agentInfo()
	})
	// 修改定位信息
	function onChangeAgentInfo(e){
		const { agentNo, agentName } = e
		if(!agentNo || !agentName){
			$infoBox.toast('区县信息缺失，请联系管理人员！')
			return
		}
		storageManage.agentInfo({ agentNo, agentName })
		agentInfo.value = { agentNo, agentName }
	}
	// 获取当前定位信息
	function getCurrentAgentInfo(){
		return agentInfo.value
	}
	// 暴露修改定位方法
	defineExpose({
		onChangeAgentInfo,
		getCurrentAgentInfo
	})
</script>

<style lang="less" scoped>
	.container{
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 30rpx 0;
		&>view{
			display: flex;
			align-items: center;
			gap: 10rpx;
			&>text{
				font-size: 28rpx;
			}
		}
		.left{
			image{
				width: 32rpx;
				height: 32rpx;
			}
		}
		.right{
			image{
				width: 28rpx;
				height: 28rpx;
			}
			text{
				color: #999999;
			}
		}
	}
</style>